<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('公告修改', '', '')"/>
    <th:block th:include="include :: wangeditor_css"/>
</head>
<body>
<form class="layui-form" action=""  th:object="${SysNotice}">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" th:value="*{id}" name="id" lay-verify="title" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input th:value="*{title}" type="text" name="title" lay-verify="title" autocomplete="off" placeholder="公告标题" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <select name="type" id="type" th:field="*{type}">
                            <option value="1">一般</option>
                            <option value="2">重要</option>
                            <option value="3">弹窗</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">内容</label>
                    <div class="layui-input-block">
                        <!-- 编辑器 DOM -->
                        <div style="border: 1px solid #ccc;">
                            <div id="editor-toolbar" style="border-bottom: 1px solid #ccc;"></div>
                            <div id="editor-text-area" style="height: 500px"></div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit=""
                    lay-filter="sysNotice-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let dtree = layui.dtree;
        let MODULE_PATH = rootPath+"/SysNoticeController";

        form.on('submit(sysNotice-update)', function (data) {
            data.field.content = editor.getHtml();
            $.ajax({
                url: MODULE_PATH+'/edit',
                data: data.field,
                dataType: 'json',
                contentType: 'application/x-www-form-urlencoded',
                type: 'post',
                success: function (result) {
                    if (result.code==200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("sysNotice-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script type="text/javascript" th:inline="javascript">
    var content = [[${SysNotice.content }]];
</script>
<th:block th:include="include :: wangeditor"/>
<script>
    const E = window.wangEditor;
    window.editor = E.createEditor({
        selector: '#editor-text-area',
        html: content ? content:"",
        mode: 'simple',
        config: {
            placeholder: 'Type here...',
            MENU_CONF: {
                uploadImage: {
                    server: '/upload-img', // 上传图片地址
                    timeout: 10 * 1000, // 10s
                    fieldName: 'file',
                    maxFileSize: 10 * 1024 * 1024, // 10M
                    base64LimitSize: 5 * 1024, // 5kb 以下插入 base64
                }
            },
            onChange() {
                // console.log(editor.getHtml())
            }
        }
    })

    window.toolbar = E.createToolbar({
        editor,
        mode: 'simple',
        selector: '#editor-toolbar',
        config: {}
    });
</script>
</body>
</html>